﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FastNetCore.Framework.Configurations
{
    /// <summary>
    /// FastNetCore框架配置选项
    /// </summary>
    public class FastNetCoreOptions
    {
        /// <summary>
        /// JSON序列化配置
        /// </summary>
        public NewtonsoftJsonOptions JsonOptions { get; set; }=new NewtonsoftJsonOptions();

        /// <summary>
        /// 路由配置
        /// </summary>
        public RouteOptions Route { get; set; }=new RouteOptions();

        /// <summary>
        /// Swagger配置
        /// </summary>
        public SwaggerOptions Swagger { get; set; } = new SwaggerOptions();

        /// <summary>
        /// 中间件配置
        /// </summary>
        public MiddlewareOptions Middleware { get; set; } = new MiddlewareOptions();
    }


    /// <summary>
    /// Newtonsoft.Json配置
    /// </summary>
    public class NewtonsoftJsonOptions
    {
        /// <summary>
        /// 日期格式（默认：yyyy-MM-dd HH:mm:ss）
        /// </summary>
        public string DateFormatString { get; set; } = "yyyy-MM-dd HH:mm:ss";

        /// <summary>
        /// 时区处理（默认：本地时区）
        /// </summary>
        public DateTimeZoneHandling DateTimeZoneHandling { get; set; } = DateTimeZoneHandling.Local;

        /// <summary>
        /// 日期解析方式（默认：自动识别日期类型）
        /// </summary>
        public DateParseHandling DateParseHandling { get; set; } = DateParseHandling.DateTime;

        /// <summary>
        /// 是否使用驼峰命名（默认：true）
        /// </summary>
        public bool UseCamelCase { get; set; } = true;

        /// <summary>
        /// 是否忽略空值（默认：true）
        /// </summary>
        public bool IgnoreNullValues { get; set; } = true;

        /// <summary>
        /// 是否忽略循环引用（默认：true）
        /// </summary>
        public bool IgnoreReferenceLoops { get; set; } = true;

        /// <summary>
        /// JSON格式化方式（默认：无缩进）
        /// </summary>
        public Formatting Formatting { get; set; } = Formatting.None;

        /// <summary>
        /// 缺少成员时的处理方式（默认：忽略）
        /// </summary>
        public MissingMemberHandling MissingMemberHandling { get; set; } = MissingMemberHandling.Ignore;

        /// <summary>
        /// 自定义转换器（可添加项目特定的转换器）
        /// </summary>
        public List<JsonConverter> Converters { get; set; } = new List<JsonConverter>();
    }

    /// <summary>
    /// 路由配置项
    /// </summary>
    public class RouteOptions
    {
        /// <summary>
        /// 是否启用小写连字符路由（默认：false）
        /// </summary>
        public bool UseLowercaseHyphenatedRoutes { get; set; } = false;

        /// <summary>
        /// 默认路由模板（如 "api/[controller]/[action]"，默认：空）
        /// </summary>
        public string DefaultRouteTemplate { get; set; } = string.Empty;
    }

    /// <summary>
    /// Swagger配置项
    /// </summary>
    public class SwaggerOptions
    {
        /// <summary>
        /// 文档标题（默认：FastNetCore API）
        /// </summary>
        public string Title { get; set; } = "FastNetCore API";
        public string Version { get; set; } = "v1";
    }

    /// <summary>
    /// 中间件配置项
    /// </summary>
    public class MiddlewareOptions
    {
        /// <summary>
        /// 是否启用HTTPS重定向（默认：true）
        /// </summary>
        public bool UseHttpsRedirection { get; set; } = true;

        /// <summary>
        /// 是否启用授权中间件（默认：true）
        /// </summary>
        public bool UseAuthorization { get; set; } = true;
    }
}
